home *** CD-ROM | disk | FTP | other *** search
/ World of Amiga / World of Amiga.iso / archive / compression / lister12.lha / ListZip.c < prev    next >
Encoding:
Text File  |  1992-04-01  |  1.2 KB  |  52 lines

  1. /* lists an Zip file's contents */
  2. BOOL
  3. ListZip(ULONG type,UBYTE *infile)
  4. {
  5.   int ct, time, date, done;
  6.   ULONG uncomp, comp, i, extra, tfiles = 0, tcomp = 0, tuncomp = 0;
  7.   UBYTE b[200],time_str[25];
  8.   FILE *fp;
  9.  
  10.   fp = OpenFile(type,infile);
  11.   ct = fread(b, 30, 1, fp);
  12.  
  13.   /* check ZIP signature and fread status */
  14.   if ((strnicmp(ZIP_SIG,b,4) != 0) || ct != 1)
  15.    {
  16.     fclose(fp);
  17.     return (WRONG_ARCHIVE);
  18.     }
  19.  
  20.   /* start listing */
  21.   InitList(ZIP,infile);
  22.  
  23.   /* parse each header block until done */
  24.   done= FALSE;
  25.   while ( ! done) {
  26.     comp = GetLong(b,21);
  27.     uncomp = GetLong(b,25);
  28.     date = b[13] * 256 + b[12];
  29.     time = b[11] * 256 + b[10];
  30.     if (MSDog(time,date,time_str) == ABORT) break;
  31.     i = (ULONG) ( b[26] + b[27] * 256);
  32.     extra = (ULONG) ( b[28] + b[29] * 256);
  33.  
  34.     /* get variable length filename */
  35.     fread(b, i, 1, fp);
  36.     b[(int) i] = '\0';
  37.     PrintList(b, uncomp, comp,&tfiles,&tcomp,&tuncomp,time_str);
  38.  
  39.     /* get variable length 'extra' bytes */
  40.     if (extra != 0) fread(b, extra, 1, fp);
  41.     fseek(fp,comp,SEEK_CUR);
  42.     ct = fread(b, 30, 1, fp);
  43.  
  44.     /* check ZIP signature */
  45.     if ((strnicmp(ZIP_SIG,b,4) != 0) || ct != 1) done = TRUE;
  46.     }
  47.  
  48.   fclose(fp);
  49.   EndStats(tfiles,tcomp,tuncomp);
  50.   return(TRUE);
  51. }
  52.